<template>
    <div class="login-page">
        <div class="login-card">
            <div class="login-title">欢迎登录</div>
            <el-form ref="formRef" :model="form" :rules="rules" label-position="top" class="login-form">
                <el-form-item label="账号" prop="username">
                    <el-input v-model="form.username" placeholder="请输入账号" />
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input v-model="form.password" placeholder="请输入密码" show-password />
                </el-form-item>
                <div class="form-extra">
                    <el-checkbox v-model="form.remember">记住我</el-checkbox>
                    <a class="link" href="javascript:void(0)" @click="onForgot">忘记密码?</a>
                </div>
                <el-button type="primary" class="submit-btn" @click="onSubmit" :loading="loading">登录</el-button>
                <div class="divider"><span>或者</span></div>
                <div class="social-row">
                    <el-button class="social-btn" @click="onTodo('微信登录')">
                        <img class="icon" src="/favicon.ico" alt="wx" /> 微信登录
                    </el-button>
                    <el-button class="social-btn" @click="onTodo('QQ登录')">
                        <img class="icon" src="/favicon.ico" alt="qq" /> QQ登录
                    </el-button>
                </div>
                <div class="register-row">
                    还没有账号? <router-link class="link" to="/register">立即注册</router-link>
                </div>
            </el-form>
        </div>
    </div>

</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

const formRef = ref()
const loading = ref(false)
const form = ref({
    username: '',
    password: '',
    remember: false,
})

const rules = {
    username: [
        { required: true, message: '请输入账号', trigger: 'blur' },
    ],
    password: [
        { required: true, message: '请输入密码', trigger: 'blur' },
    ],
}

const onForgot = () => {
    ElMessage.info('请联系管理员重置密码')
}

const onSubmit = async () => {
    await formRef.value?.validate()
    loading.value = true
    try {
        // TODO: 调用实际登录接口
        ElMessage.success('登录成功（示例）')
    } finally {
        loading.value = false
    }
}

const onTodo = (name: string) => {
    ElMessage.info(`${name} 功能待开发`)
}
</script>

<style scoped>
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f7fa;
    background-image: url('@/assets/img/other/backgroud.png');
    background-repeat: no-repeat;
    background-position: center center;
    background-size: auto;
}

.login-card {
    width: 450px;
    max-width: 92vw;
    min-height: 460px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
    padding: 32px 36px 28px;
}

.login-title {
    font-size: 28px;
    font-weight: 800;
    text-align: center;
    margin-bottom: 8px;
    color: #111827;
}

.login-form {
    margin-top: 12px;
}

.form-extra {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.submit-btn {
    width: 100%;
    height: 36px;
    margin-top: 4px;
}

.divider {
    display: flex;
    align-items: center;
    margin: 16px 0 12px;
    color: #9ca3af;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e5e7eb;
}

.divider span {
    padding: 0 12px;
}

.social-row {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.social-btn {
    flex: 1;
}

.icon {
    width: 16px;
    height: 16px;
    margin-right: 6px;
}

.register-row {
    text-align: center;
    margin-top: 16px;
    color: #6b7280;
}

.link {
    color: #3b82f6;
    text-decoration: none;
}

.link:hover,
.link:focus {
    text-decoration: none;
}

@media (max-width: 480px) {
    .login-card {
        padding: 24px 20px 20px;
    }
}

/* 取消浏览器自动填充底色（Chrome/Safari/Edge） */
:deep(input:-webkit-autofill),
:deep(input:-webkit-autofill:hover),
:deep(input:-webkit-autofill:focus),
:deep(input:-webkit-autofill:active) {
    -webkit-text-fill-color: inherit !important;
    transition: background-color 9999s ease-out 0s !important;
    box-shadow: 0 0 0 1000px transparent inset !important;
    caret-color: inherit;
}

/* 兼容新内核伪类，移除自动填充高亮 */
:deep(input:-internal-autofill-selected) {
    appearance: none !important;
    background-image: none !important;
    background-color: transparent !important;
    color: inherit !important;
}
</style>